package springboot.study.project.common;

public enum ResultEnum implements ErrorCode{
    SUCCESS(200, "执行成功！"),

    ERROR(999999, "执行失败！"),
    ERROR_100001(100001, "用户不存在！"),
    ERROR_100002(100002, "用户密码不正确！"),
    ERROR_100003(100003, "成功"),

    E_100104(100101, "传入参数与接口不匹配"),
    CUSTOM(999998, "自定义异常"),
    E_200005(200005,"参数缺失"),
    E_200006(200006,"传入参数格式不正确"),
    /**
     * 未知错误
     */
    NO_CORE(500000, "缺少核心参数"),
    UNKNOWN(999999, "未知错误");

    private int code;
    private String msg;

    ResultEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return null;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static ResultEnum setErrorCode(int code) {
        for (ResultEnum errorCode : ResultEnum.values()) {
            if (errorCode.getCode() == code) {
                return errorCode;
            }
        }
        return null;
    }
}
